<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>

</body>
<script>
    window.onload = function () {
        var system_url = window.location.pathname.indexOf('/meetingCore') > -1 ? '/meetingapicoreweb' : '/meetingapiweb';
        function getUrlParam(param) {
            var reg = new RegExp("(^|&)" + param + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substring(1).match(reg); //匹配目标参数
            if (r != null) return decodeURI(r[2]);
            return null; //返回参数值
        }
        var meetingMoid = getUrlParam('meetingMoid');
        var isVideoMeeting = getUrlParam('isVideoMeeting');

        function setCookieInfo(callBack) {
            var url = system_url + "/cookie_info?meeting_moid=" + meetingMoid + '&type=1'

            var _tmp = new window.XMLHttpRequest()
            _tmp.open('GET', url, false)
            _tmp.onreadystatechange = function () {
                if (_tmp.readyState === 4 && _tmp.status === 200) {
                    try {
                        var res = JSON.parse(_tmp.responseText)
                        if (res.success && res.data) {
                            try {
                                var meeting_machine_link = localStorage.getItem("meeting_machine_link")
                                if (meeting_machine_link) {
                                    meeting_machine_link = JSON.parse(meeting_machine_link)
                                } else {
                                    meeting_machine_link = {
                                        list: {},  //会议与机房的关联表
                                        meeting_machine_moid: '' //存储当前最新机房的moid
                                    }
                                }
                                var meeting_machine_moid = res.data
                                meeting_machine_link.list[meetingMoid] = meeting_machine_moid
                                meeting_machine_link.meeting_machine_moid = meeting_machine_moid

                                localStorage.setItem("meeting_machine_link", JSON.stringify(meeting_machine_link))
                            } catch (e) {
                                console.error("存储会议、机房关系报错", e)
                            }
                            callBack()
                        } else {
                            if (
                                ((res.errorCode &&
                                    (res.errorCode == 100013 ||
                                        res.errorCode == 100012 ||
                                        res.errorCode == 100011 ||
                                        res.errorCode == 100010)) ||
                                    (res.error_code &&
                                        (res.error_code == 100013 ||
                                            res.error_code == 100012 ||
                                            res.error_code == 100011 ||
                                            res.error_code == 100010)))
                            ) {

                                window.location.href = window.location.origin + '/portal/login'

                            } else {
                                callBack()
                            }
                        }

                    } catch (e) {
                        window.location.href = window.location.origin + '/portal/login'
                    }
                } else {
                    window.location.href = window.location.origin + '/portal/login'
                }
            }
            _tmp.send(null)


        }
        if (isVideoMeeting == 0) {
            var _tmp2 = new window.XMLHttpRequest()
            var url2 = system_url + "/open_url"
            _tmp2.open('GET', url, false)
            _tmp2.onreadystatechange = function(){
                var preUrl = '/meeting';
                if (_tmp2.readyState === 4 && _tmp2.status === 200) {
                        try {
                            var res = JSON.parse(_tmp.responseText)
                            if (res.success) {
                                var preUrl = res.data;
                                setCookieInfo(function () {
                                    window.location = (preUrl + `/meeting/meetingSpace/${meetingMoid}`);
                                })
                            } else {
                                setCookieInfo(function () {
                                    window.location = (`/meeting/meeting/meetingSpace/${meetingMoid}`);
                                })
                            }

                        } catch (e) {
                            setCookieInfo(function () {
                                window.location = (`/meeting/meeting/meetingSpace/${meetingMoid}`);
                            })
                        }
                } else {
                    setCookieInfo(function () {
                        window.location = (`/meeting/meeting/meetingSpace/${meetingMoid}`);
                    })
                }
            }
            _tmp2.send(null)
        } else {
            setCookieInfo(function () {
                window.location = (`/meeting/meeting/meetingSpace/${meetingMoid}`);
            })
        }

    }
</script>

</html>
